package com.hclc.yxb.controller;

import com.hclc.entity.model.result.ResultEntity;
import com.hclc.yxb.service.ConsoleUserInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotBlank;

/**
 * @ClassName PwlAddProductController
 * @Author: yurj
 * @Mail：1638234804@qq.com
 * @Date: Create in 18:18 2020/8/10
 * @version: 1.0
 */
@Api(tags = "WEB-1.0-sys-login", description = "WEB-后台用户登录相关")
@RestController
@RequestMapping("console/user")
@Validated
public class UserInfoController {

    @Autowired
    private ConsoleUserInfoService consoleUserInfoService;

    /**
     * 后台管理员登录
     *
     * @param username
     * @param password
     * @return com.hclc.pwl.model.result.ResultEntity
     * @author yurj
     * @mail 1638234804@qq.com
     * @version 1.0
     * @date 2020/8/18 10:53
     */
    @ApiOperation("用户登录")
    @PostMapping(value = "/login", produces = {MediaType.APPLICATION_JSON_VALUE})
    public ResultEntity userLogin(HttpServletRequest request, HttpServletResponse response, @ApiParam(value = "用户名", defaultValue = "admin") @NotBlank(message = "用户名不能为空") @RequestParam String username, @ApiParam(value = "密码", defaultValue = "e10adc3949ba59abbe56e057f20f883e") @NotBlank(message = "登录密码不能为空") @RequestParam String password) {
        return ResultEntity.ResultSuccess(consoleUserInfoService.selectUserInfo(request,response,username,password));
    }
}
